<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <title>pcount</title>
    <link rel="stylesheet" type="text/css" href="csound.css" />
    <meta name="generator" content="DocBook XSL Stylesheets V1.78.1" />
    <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" />
    <link rel="up" href="OpcodesTop.html" title="Orchestra Opcodes and Operators" />
    <link rel="prev" href="pconvolve.html" title="pconvolve" />
    <link rel="next" href="pdclip.html" title="pdclip" />
  </head>
  <body>
    <div class="navheader">
      <table width="100%" summary="Navigation header">
        <tr>
          <th colspan="3" align="center">pcount</th>
        </tr>
        <tr>
          <td width="20%" align="left"><a accesskey="p" href="pconvolve.html">Prev</a> </td>
          <th width="60%" align="center">Orchestra Opcodes and Operators</th>
          <td width="20%" align="right"> <a accesskey="n" href="pdclip.html">Next</a></td>
        </tr>
      </table>
      <hr />
    </div>
    <div class="refentry">
      <a id="pcount"></a>
      <div class="titlepage"></div>
      <a id="IndexPcount" class="indexterm"></a>
      <div class="refnamediv">
        <h2>
          <span class="refentrytitle">pcount</span>
        </h2>
        <p>pcount — 
      Returns the number of pfields belonging to a note event.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp133402608"></a>
        <h2>Description</h2>
        <p>
      <span class="emphasis"><em>pcount</em></span> returns the number of pfields belonging to a note event.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp133404352"></a>
        <h2>Syntax</h2>
        <pre class="synopsis">icount <span class="command"><strong>pcount</strong></span></pre>
      </div>
      <div class="refsect1">
        <a id="idp133406432"></a>
        <h2>Initialization</h2>
        <p>
      <span class="emphasis"><em>icount</em></span> - stores the number of pfields for the current note event.
    </p>
        <div class="note" style="margin-left: 0.5in; margin-right: 0.5in;">
          <table border="0" summary="Note">
            <tr>
              <td rowspan="2" align="center" valign="top" width="25">
                <img alt="[Note]" src="images/note.png" />
              </td>
              <th align="left">Note</th>
            </tr>
            <tr>
              <td align="left" valign="top">
                <p>
        Note that the reported number of pfields is not necessarily what's explicitly written in the score, but the pfields available to the instrument through mechanisms like <a class="link" href="ScoreTop.html#ScoreCarry" title="Carry"><em class="citetitle">pfield carry</em></a>.
      </p>
              </td>
            </tr>
          </table>
        </div>
      </div>
      <div class="refsect1">
        <a id="idp133410384"></a>
        <h2>Examples</h2>
        <p>
      Here is an example of the pcount opcode. It uses the file <a class="ulink" href="examples/pcount.csd" target="_top"><em class="citetitle">pcount.csd</em></a>.

      </p>
        <div class="example">
          <a id="idp133412240"></a>
          <p class="title">
            <strong>Example 612. Example of the pcount opcode.</strong>
          </p>
          <div class="example-contents">
            <p>See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags.</p>
            <pre class="programlisting">
<span class="csdtag">&lt;CsoundSynthesizer&gt;</span>
<span class="csdtag">&lt;CsOptions&gt;</span>
<span class="comment">; Select audio/midi flags here according to platform</span>
-odac  <span class="comment">;;;realtime audio</span>
<span class="comment">;-iadc    ;;;uncomment -iadc if realtime audio input is needed too</span>
<span class="comment">; For Non-realtime ouput leave only the line below:</span>
<span class="comment">; -o pcount.wav -W ;;; for file output any platform</span>
<span class="csdtag">&lt;/CsOptions&gt;</span>
<span class="csdtag">&lt;CsInstruments&gt;</span>

<span class="ohdr">sr</span> <span class="op">=</span> 44100
<span class="ohdr">ksmps</span> <span class="op">=</span> 32
<span class="ohdr">nchnls</span> <span class="op">=</span> 2
<span class="ohdr">0dbfs</span>  <span class="op">=</span> 1

<span class="comment">; This UDO returns a pfield value but returns 0 if it does not exist.</span>
<span class="oblock">opcode</span>  mypvalue, i, <span class="opc">i</span>
	index  <span class="opc">xin</span>
	inum   <span class="opc">pcount</span>
	<span class="octrl">if</span>	  (index <span class="op">&gt;</span> inum)  then
		iout <span class="op">=</span> 0.0
	<span class="octrl">else</span>
		iout <span class="opc">pindex</span> index
	<span class="octrl">endif</span>
	
	<span class="opc">xout</span>	iout
<span class="oblock">endop</span>
	
<span class="comment">; Envelope UDO that reads parameters from a flexible number of pfields</span>
<span class="comment">; Syntax:   kenv  flexlinseg  ipstart</span>
<span class="comment">;           ipstart is the first pfield of the envelope</span>
<span class="comment">;               parameters.  Reads remaining pfields (up to 21 of them).</span>
<span class="comment">;           kenv is the output envelope.</span>

<span class="oblock">opcode</span>  flexlinseg, k, <span class="opc">i</span>
	ipstart <span class="opc">xin</span>
	
	iep1   mypvalue	ipstart
	iep2   mypvalue	ipstart <span class="op">+</span> 1
	iep3   mypvalue	ipstart <span class="op">+</span> 2
	iep4   mypvalue	ipstart <span class="op">+</span> 3
	iep5   mypvalue	ipstart <span class="op">+</span> 4
	iep6   mypvalue	ipstart <span class="op">+</span> 5
	iep7   mypvalue	ipstart <span class="op">+</span> 6
	iep8   mypvalue	ipstart <span class="op">+</span> 7
	iep9   mypvalue	ipstart <span class="op">+</span> 8
	iepa   mypvalue	ipstart <span class="op">+</span> 9
	iepb   mypvalue	ipstart <span class="op">+</span> 10
	iepc   mypvalue	ipstart <span class="op">+</span> 11
	iepd   mypvalue	ipstart <span class="op">+</span> 12
	iepe   mypvalue	ipstart <span class="op">+</span> 13
	iepf   mypvalue	ipstart <span class="op">+</span> 14
	iepg   mypvalue	ipstart <span class="op">+</span> 15
	ieph   mypvalue	ipstart <span class="op">+</span> 16
	iepi   mypvalue	ipstart <span class="op">+</span> 17
	iepj   mypvalue	ipstart <span class="op">+</span> 18
	iepk   mypvalue	ipstart <span class="op">+</span> 19
	iepl   mypvalue	ipstart <span class="op">+</span> 20

	kenv   <span class="opc">linseg</span>	 iep1, iep2, iep3, iep4, iep5, iep6, iep7, iep8, \
	                   iep9, iepa, iepb, iepc, iepd, iepe, iepf, iepg, \
	                   ieph, iepi, iepj, iepk, iepl	
	<span class="opc">xout</span>   kenv
<span class="oblock">endop</span>
	
<span class="oblock">instr</span> 1
<span class="comment">; This instrument only requires 3 pfields but can accept up to 24.</span>
<span class="comment">; (You will still get warnings about more than 3).	</span>
kenv flexlinseg  4		<span class="comment">; envelope params start at p4</span>
aout <span class="opc">oscili</span> kenv<span class="op">*</span>.5, 256, 1
     <span class="opc">outs</span> aout, aout

<span class="oblock">endin</span>
<span class="csdtag">&lt;/CsInstruments&gt;</span>
<span class="csdtag">&lt;CsScore&gt;</span>
<span class="stamnt">f</span>1  0 8192 10 1

<span class="stamnt">i</span>1  0 2  0.0 1.0 1.0 1.0 0.0
<span class="stamnt">i</span>1  2 2  0.0 0.1 1.0 1.0 1.0 0.1 0.0
<span class="stamnt">i</span>1  4 2  0.0 0.5 0.0	  			<span class="comment">; one problem is that "missing" pfields carry</span>
<span class="stamnt">i</span>1  6 2  0.0 0.5 0.0 !	  			<span class="comment">; now we can fix this problem with !</span>
<span class="stamnt">i</span>1  8 10  0.0  3.0 1.0  0.3 0.1  0.3 1.0  0.3 0.1  0.3 1.0  0.3 0.1  0.8 0.9  5.0 0.0

<span class="stamnt">e</span>
<span class="csdtag">&lt;/CsScore&gt;</span>
<span class="csdtag">&lt;/CsoundSynthesizer&gt;</span>
</pre>
          </div>
        </div>
        <p><br class="example-break" />
    </p>
        <p>
      The example will produce the following output:
      </p>
        <pre class="screen">
WARNING: instr 1 uses 3 p-fields but is given 8
B  0.000 ..  2.000 T  2.000 TT  2.000 M:  0.49966  0.49966
WARNING: instr 1 uses 3 p-fields but is given 10
B  2.000 ..  4.000 T  4.000 TT  4.000 M:  0.50000  0.50000
WARNING: instr 1 uses 3 p-fields but is given 10
B  4.000 ..  6.000 T  6.000 TT  6.000 M:  0.49943  0.49943
WARNING: instr 1 uses 3 p-fields but is given 6
B  6.000 ..  8.000 T  8.000 TT  8.000 M:  0.00000  0.00000
WARNING: instr 1 uses 3 p-fields but is given 20
B  8.000 .. 18.000 T 18.000 TT 18.000 M:  0.49994  0.49994
      </pre>
        <p>
      The warnings occur because pfields are not used explicitly by the instrument.
    </p>
      </div>
      <div class="refsect1">
        <a id="idp133419072"></a>
        <h2>See Also</h2>
        <p>
      <a class="link" href="pindex.html" title="pindex"><em class="citetitle">pindex</em></a>
    </p>
      </div>
      <div class="refsect1">
        <a id="idp133421296"></a>
        <h2>Credits</h2>
        <p>Example by: Anthony Kozar</p>
        <p>Dec. 2006</p>
      </div>
    </div>
    <div class="navfooter">
      <hr />
      <table width="100%" summary="Navigation footer">
        <tr>
          <td width="40%" align="left"><a accesskey="p" href="pconvolve.html">Prev</a> </td>
          <td width="20%" align="center">
            <a accesskey="u" href="OpcodesTop.html">Up</a>
          </td>
          <td width="40%" align="right"> <a accesskey="n" href="pdclip.html">Next</a></td>
        </tr>
        <tr>
          <td width="40%" align="left" valign="top">pconvolve </td>
          <td width="20%" align="center">
            <a accesskey="h" href="index.html">Home</a>
          </td>
          <td width="40%" align="right" valign="top"> pdclip</td>
        </tr>
      </table>
    </div>
  </body>
</html>
